package nz.co.doherty.gwtpbreadcrumbs.server.handler.product;

import nz.co.doherty.gwtpbreadcrumbs.shared.entity.Product;
import nz.co.doherty.gwtpbreadcrumbs.shared.rpc.product.ProductListAction;
import nz.co.doherty.gwtpbreadcrumbs.shared.rpc.product.ProductListResult;

import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
import com.philbeaudoin.gwtp.dispatch.server.ExecutionContext;
import com.philbeaudoin.gwtp.dispatch.server.actionHandler.ActionHandler;
import com.philbeaudoin.gwtp.dispatch.shared.ActionException;

public class ProductListHandler implements ActionHandler<ProductListAction, ProductListResult> {
	
	@Override
	public ProductListResult execute(ProductListAction action,
			ExecutionContext context) throws ActionException {

		Objectify ofy = ObjectifyService.begin();
		return new ProductListResult(ofy.query(Product.class).list());

	}

	@Override
	public void undo(ProductListAction action, ProductListResult result,
			ExecutionContext context) throws ActionException {
		// TODO Auto-generated method stub

	}

	@Override
	public Class<ProductListAction> getActionType() {
		return ProductListAction.class;
	}

}
